package com.kmxd.ams.core.exception;

import javax.validation.constraints.NotNull;

/**
 * 抛出异常，并返回数据给调用方
 *
 * @author zuolg
 */
public class ReturnDataException extends AbstractException {

  public ReturnDataException(
      @NotNull final LogInfo recordInfo, @NotNull String errorCode, String data) {
    super(recordInfo, errorCode, data);
    this.code = errorCode;
    this.msg = data;
    this.debugMessage = data;
  }

  public ReturnDataException(@NotNull final LogInfo recordInfo, @NotNull String errorCode) {
    super(recordInfo, errorCode);
    this.code = errorCode;
  }

  public static ReturnDataException instance(@NotNull String errorCode) {
    return new ReturnDataException(LogInfo.newCallerInstance(), errorCode);
  }

  public static ReturnDataException instance(@NotNull String errorCode, String debugMessage) {
    return new ReturnDataException(LogInfo.newCallerInstance(), errorCode, debugMessage);
  }

  public static void throwException(@NotNull final LogInfo recordInfo, @NotNull String errorCode) {
    throw new ReturnDataException(recordInfo, errorCode);
  }

  public static void throwException(@NotNull String errorCode, String debugMessage) {
    throw new ReturnDataException(LogInfo.newCallerInstance(), errorCode, debugMessage);
  }
}
